<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class GivePay
{
    protected $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

    protected function script()
    {
        return <<<SCRIPT

layui.use('layer', function(){
        var layer = layui.layer;
        $('.givepay').click(function () {
           var that = this;
           var id = $(that).attr('data-id');
           var index = layer.confirm('确定更改状态吗?',{title:'提示'} ,function(index){
                $.ajax({
                    url: '/admin/pay/state/'+id,
                    type: 'get',
                    success: function(res){
                        alert(res.info);
                        layer.close(index);
                        $(that).prop('disabled', true).css('backgroundColor', 'black');
                    }
                });
           });      
       });
});

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "&nbsp;<a href='javascript:void(0);'><button  data-id='{$this->id}' class='givepay layui-btn layui-btn-danger layui-btn-xs'>打款</button></a>";

    }

    public function __toString()
    {
        return $this->render();
    }
}